package com.tedu.boot04.controller;
import com.tedu.boot04.Mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tedu.boot04.entity.User;
@RestController
public class UserController {
    @Autowired
    UserMapper mapper;
    @RequestMapping("/reg")
    public String reg(User user){
        //通过用户输入的用户名查询
        User u = mapper.selectByUsername(user.getUsername());
        if (u!=null){
            return "用户名存在！";
        }
        mapper.insert(user);
        return "注册成功";
    }

    @RequestMapping("/login")
    public String login(User user){
        User u = mapper.selectByUsername(user.getUsername());
        if (u!=null){
            if (user.getPassword().equals(u.getPassword())){
                return "登陆成功";
            }
            return "密码错误";
        }
        return "用户不存在";
    }
}
